

import React, { Component } from "react";
import Grid from '../../../../components/display/grid';
import { Form, Input, Row, Col, Button } from 'antd';
import SaasModal from '../../../../components/display/SaasModal';
import {stubGroupList} from '../../../../fetch/fetchApi';
const FormItem = Form.Item;
const createForm = Form.create;
// const {TextArea} = Input;

class StubModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            refresh:0,
            params:{},
        };
        this.columns2=[
            {
                title: '电站名称',
                dataIndex: 'name',
                key: '0',
            },
            {
                title: '操作',
                key: '3',
                width:120,
                render: (text,record) => (
                    <span>
                        <a onClick={()=>{this.choose(text)}}>添加</a>
                    </span>
                )
            },
        ]
    }

    componentWillReceiveProps(nextProps){
        
    }
    choose=(text)=>{
        this.props.addItem(text);
    }


    handleSubmit =(e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, values) => {
            if (!!err) {
                return;
            }
            console.log(values);
            this.setState({
                params:Object.assign(this.state.params,values),
                refresh:this.state.refresh+1
            })
        });
    };


    render() {
        const {getFieldDecorator} = this.props.form;
        return(
            <SaasModal visible={this.props.visible} handleCancel={this.props.handleCancel} title={'添加权限'}>
                <form form={this.props.form}>
                    <Row gutter={16}>
                        <Col xl={5}>
                            <FormItem
                            >
                                {getFieldDecorator('name')(
                                    <Input placeholder={'请输入电站名称'}/>
                                )}
                            </FormItem>
                        </Col>
                        <Col xl={4}>
                            <FormItem
                            
                            >
                                <Button style={{marginRight:4}} type="primary" htmlType="submit" onClick={this.handleSubmit}>{'搜索'}</Button>
                            </FormItem>
                        </Col>
                    </Row>
                </form>
                <Grid className={'sc-table'} columns={this.columns2} params={this.state.params} fetchData={stubGroupList} refresh={this.state.refresh}/>
            </SaasModal>
        )
    }
}
StubModal = createForm()(StubModal);
export default StubModal;